<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@ include file="/WEB-INF/view/common/loginCheck.jspf" %>
<div class="easyui-panel" data-options="fit:true,footer:'#roleEditBtns'" style="padding:10px;">
    <form id="roleEditForm" method="post">
		 <table style="width:100%">
             <tr>
                 <td>父角色:</td>
                 <td>
                 	<input type="hidden" name="id" value="${entity.id}" />
                 	<input id="parentRole" type="hidden" name="parentId" value="${entity.parentId}" />
                 	<input id="roleSelectTree" type="text" style="width:180px;">
                 	<a href="javascript:void(0)" title="清空父角色" class="easyui-linkbutton" onclick="clearParentRole();" data-options="iconCls:'icon-no'"></a>
                 </td>
             </tr>
             <tr>
                 <td>名称:</td>
                 <td>
                 	<input class="easyui-textbox" type="text" name="name" value="${entity.name}" data-options="required:true" />
                 </td>
             </tr>
             <tr>
                 <td>描述:</td>
                 <td>
                 	<input class="easyui-textbox" type="text" name="description" size="60" value="${entity.description}" />
                 </td>
             </tr>
         </table>
	</form>
</div>
<t:permission codes="ROLE-VIEW,ROLE-MODIFY">
<div id="roleEditBtns" style="text-align:right;padding:2px;">
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveRole();">保存</a>
</div>
</t:permission>

<script type="text/javascript">
	$(function () {
		$('#roleSelectTree').combotree({
		    url: '${ROOT}/account/role/tree?_rt=' + new Date().getTime(),
		    onSelect: function (node) {
		    	$('#parentRole').val(node.id);
		    },
		    onLoadSuccess: function (node, data) {
		    	$('#roleSelectTree').combotree('setValue', '${entity.parentId}');
		    }
		});
		
		$('#roleEditForm').form({
		    url:'${ROOT}/account/role/save?_rt=' + new Date().getTime(),
		    ajax: true,
		    onSubmit: function() {
		    	return $(this).form('enableValidation').form('validate');
		    },
		    success:function(data) {
		    	var json = eval('(' + data + ')');
				if (json.success) {
		        	refresh();
		        	$('#roleEditDlg').dialog('close');
					APP.message('保存成功');
		        } else {
		        	 APP.error(json.msg);
		        }
		    }
		});
	});
	
	function clearParentRole() {
		$('#roleSelectTree').combotree('clear');
		$('#parentRole').val('');
	}
	
	function saveRole() {
		$('#roleEditForm').submit();
	}
	
	function closeDlg() {
		$('#roleEditDlg').dialog('close');
	}
</script>